package StudyCode.summary.BufferAndChannel;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ReadStringUsingBufferedReader {
	public static void main(String[] argv) {
		String fileName = "E:/迅雷下载/test1.txt";
		System.out.println(readString(fileName));
	}

	private static String readString(String fileName) {
		File file = new File(fileName);
		return readString(file);
	}

	private static String readString(File file) {
		StringBuilder builder = new StringBuilder();
		if (!file.exists()) {
			System.err.println("文件不存在 " + file);
		}

		try {
			BufferedReader in = new BufferedReader(new FileReader(file));
			String str;
			while ((str = in.readLine()) != null) {
				builder.append(str);
			}
			in.close();
		} catch (IOException e) {
			e.getStackTrace();
		}
		return builder.toString();
	}
}
